import { request } from 'umi';

export async function fetchAll(daoName: string, sorter: API.OrderItem[], filters: string) {
  const data = new FormData();
  if (sorter && sorter.length > 0) {
    data.append('OrderItems', JSON.stringify(sorter));
  }
  if (filters && filters.length > 0) {
    data.append('where', filters);
  }
  return request<Record<string, any>[]>(`/api/restricted/FindAll/${daoName}`, {
    method: 'POST',
    body: data,
  });
}
export async function fetch(
  daoName: string,
  page: number,
  pageSize: number,
  sorter: API.OrderItem[],
  filters: API.WhereCause[],
  permID: number,
) {
  const data = new FormData();
  if (sorter && sorter.length > 0) {
    data.append('OrderItems', JSON.stringify(sorter));
  }
  if (filters && filters.length > 0) {
    data.append('WhereCauses', JSON.stringify(filters));
  }
  data.append('PermID', '' + permID);
  return request<API.ListData>(`/api/restricted/Find/${daoName}/${page}/${pageSize}`, {
    method: 'POST',
    body: data,
  });
}

export async function fetchTable(
  tableName: string,
  valueTpl: string,
  optionTpl: string,
  searchColumns: string[],
  value: string,
) {
  const data = new FormData();
  data.append('ValueTpl', valueTpl);
  data.append('OptionTpl', optionTpl);
  data.append('value', value);
  data.append('SearchColumns', JSON.stringify(searchColumns));
  return request<Record<string, any>[]>(`/api/restricted/FindTable/${tableName}`, {
    method: 'POST',
    body: data,
  });
}

export async function fetchOption(daoName: string, filters: string, sorter: API.OrderItem[]) {
  const data = new FormData();
  if (filters && filters.length > 0) {
    data.append('where', filters);
  }
  if (sorter && sorter.length > 0) {
    data.append('OrderItems', JSON.stringify(sorter));
  }
  return request<object[]>(`/api/restricted/FindAll/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

/**导出报表数据 */
export async function exporData(
  daoName: string,
  whereCauses: API.WhereCause[],
  orderItems: API.OrderItem[],
  columnHeaders: API.ColumnHeader[],
  permID: number,
) {
  const data = new FormData();
  data.append('WhereCauses', JSON.stringify(whereCauses));
  data.append('OrderItems', JSON.stringify(orderItems));
  data.append('ColumnHeaders', JSON.stringify(columnHeaders));
  data.append('PermID', '' + permID);
  return request(`/api/restricted/ExportXlsx/${daoName}`, {
    method: 'POST',
    body: data,
    responseType: 'blob',
  });
}

export async function removeKeys(daoName: string, keys: any[]) {
  const data = new FormData();
  data.append('PrimaryKeyValues', JSON.stringify(keys));
  return request(`/api/restricted/Deletes/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export async function removeEntity(daoName: string, values: object) {
  const data = new FormData();
  data.append('Entity', JSON.stringify(values));
  return request(`/api/restricted/Delete/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export async function patch(daoName: string, values: object) {
  const data = new FormData();
  data.append('Entity', JSON.stringify(values));
  return request(`/api/restricted/Update/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export async function create(daoName: string, values: object) {
  const data = new FormData();
  data.append('Entity', JSON.stringify(values));
  return request(`/api/restricted/Add/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

export async function submitDatas(
  daoName: string,
  newDatas: object,
  updateDatas: object,
  deleteDatas: object,
) {
  const data = new FormData();
  data.append('NewDatas', JSON.stringify(newDatas));
  data.append('UpdateDatas', JSON.stringify(updateDatas));
  data.append('DeleteDatas', JSON.stringify(deleteDatas));
  return request(`/api/restricted/SaveDatas/${daoName}`, {
    method: 'POST',
    body: data,
  });
}

/**对公存款绩费系数--添加 */
export function AddCompAccoJfxs(acid: number, tzxs: number, tzxs2: number) {
  const data = new FormData();
  data.append('ACID', '' + acid);
  data.append('TZXS', '' + tzxs);
  data.append('TZXS2', '' + tzxs2);
  return request(`/api/restricted/AddCompAccoJfxs`, {
    method: 'POST',
    body: data,
  });
}

/**对公存款绩费系数--删除 */
export function DeleteCompAccoJfxs(acid: number) {
  const data = new FormData();
  data.append('ACID', '' + acid);
  return request(`/api/restricted/DeleteCompAccoJfxs`, {
    method: 'POST',
    body: data,
  });
}

/**零售不良认定 */
export function UpIndiClieIsbl(KHID: number) {
  const data = new FormData();
  data.append('KHID', '' + KHID);
  return request(`/api/restricted/UpIndiClieIsbl/clie`, {
    method: 'POST',
    body: data,
  });
}
/**零售不良认定删除 */
export function UpIndiClieIsbl1(KHID: number) {
  const data = new FormData();
  data.append('KHID', '' + KHID);
  return request(`/api/restricted/UpIndiClieIsbl/clie1`, {
    method: 'POST',
    body: data,
  });
}
/**对公不良认定 */
export function UpCompClieblgm(khid: number, isbl: number, isgm: number) {
  const data = new FormData();
  data.append('KHID', '' + khid);
  data.append('isbl', '' + isbl);
  data.append('isgm', '' + isgm);
  return request(`/api/restricted/UpCompClieblgm/clie`, {
    method: 'POST',
    body: data,
  });
}

export function DelClieblgm(khid: number) {
  const data = new FormData();
  data.append('KHID', '' + khid);
  return request(`/api/restricted/DelClieblgm/clie`, {
    method: 'POST',
    body: data,
  });
}

/**对公不良认定--关联对公户 */
export function AddCompbldkDgh(khid: number, id: number) {
  const data = new FormData();
  data.append('KHID', '' + khid);
  data.append('ID', '' + id);
  return request(`/api/restricted/AddCompbldkClie/dgh`, {
    method: 'POST',
    body: data,
  });
}

/**对公不良认定--删除关联对公户 */
export function DelCompbldkDgh(id: number) {
  const data = new FormData();
  data.append('ID', '' + id);
  return request(`/api/restricted/DelCompbldkClie/dgh`, {
    method: 'POST',
    body: data,
  });
}
/**对公不良认定--关联个人户 */
export function AddCompbldkGrh(khid: number, id: number) {
  const data = new FormData();
  data.append('KHID', JSON.stringify(khid));
  data.append('ID', JSON.stringify(id));
  return request(`/api/restricted/AddCompbldkClie/grh`, {
    method: 'POST',
    body: data,
  });
}

/**对公不良认定--删除关联个人户 */
export function DelCompbldkGrh(id: number) {
  const data = new FormData();
  data.append('ID', '' + id);
  return request(`/api/restricted/DelCompbldkClie/grh`, {
    method: 'POST',
    body: data,
  });
}

//员工部门调动，修改业绩转移方式
export function UpdateUserOrgan(
  ygdd: number,
  YJBD: string,
  NEMID1: number,
  ZB1: number,
  NEMID2: number,
  ZB2: number,
) {
  const data = new FormData();
  data.append('ID', '' + ygdd);
  data.append('YJBD', YJBD);
  data.append('NEMID1', NEMID1 ? '' + NEMID1 : '');
  data.append('ZB1', ZB1 ? '' + ZB1 : '0');
  data.append('NEMID2', NEMID2 ? '' + NEMID2 : '');
  data.append('ZB2', ZB2 ? '' + ZB2 : '0');
  return request(`/api/restricted/UserOrganUpdate/UserOrgan`, {
    method: 'POST',
    body: data,
  });
}

//业绩转移选择：部分业绩留下时，判断业绩是否导入
export function UserOrganImportDivi(ygdd: number) {
  const data = new FormData();
  data.append('ID', '' + ygdd);
  return request(`/api/restricted/UserOrganDiviSel/UserOrgan`, {
    method: 'POST',
    body: data,
  });
}

//处理分户修改
export function UpdateDiviPro(dateString: string) {
  const data = new FormData();
  data.append('Date', dateString);
  return request(`/api/restricted/UpDiviProcess/Divi`, {
    method: 'POST',
    body: data,
  });
}
export function UpdateZSRQ(day: number) {
  const data = new FormData();
  data.append('day', '' + day);
  return request(`/api/restricted/UpDiviProcess/UpdateZSRQ`, {
    method: 'POST',
    body: data,
  });
}
export function DefaultDate() {
  const data = new FormData();
  return request(`/api/restricted/UpDiviProcess/DefaultDate`, {
    method: 'POST',
    body: data,
  });
}
export function GetBigTablePieItems() {
  return request<Record<string, string[]>>(`/api/BigTable/pieItems`, {
    method: 'GET',
  });
}

/**存单质押--修改 */
export function AddCompCdzy(acid: number) {
  const data = new FormData();
  data.append('ACID', '' + acid);
  return request(`/api/restricted/AddCompCdzy`, {
    method: 'POST',
    body: data,
  });
}

/**存单质押--恢复 */
export function DeleteCompCdzy(acid: number) {
  const data = new FormData();
  data.append('ACID', '' + acid);
  return request(`/api/restricted/DeleteCompCdzy`, {
    method: 'POST',
    body: data,
  });
}

//获取年和季度
export function GetSjcjzt(nian: number, jidu: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('JIDU', '' + jidu);
  return request(`/api/restricted/GetSjcjzt`, {
    method: 'POST',
    body: data,
  });
}

//获取年和季度
export function SetSjcjzt(nian: number, jidu: number, zt: boolean) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('JIDU', '' + jidu);
  data.append('ZT', zt ? '1' : '0');
  return request(`/api/restricted/SetSjcjzt`, {
    method: 'POST',
    body: data,
  });
}

//保存中后台操作人
export function SaveZhtCzr(zhtczr: Record<string, any>, bm: Record<string, any>) {
  console.log(zhtczr);
  const data = new FormData();
  data.append('CZR', '' + zhtczr);
  data.append('BMID', '' + bm);
  return request(`/api/restricted/SaveZhtCzr`, {
    method: 'POST',
    body: data,
  });
}

//保存经营单位操作人
export function SaveJydwCzr(jydwczr: Record<string, any>, zb: Record<string, any>) {
  console.log(jydwczr);
  const data = new FormData();
  data.append('CZR', '' + jydwczr);
  data.append('ZBID', '' + zb);
  return request(`/api/restricted/SaveJydwCzr`, {
    method: 'POST',
    body: data,
  });
}

/**中后台获取操作人状态 */
export function AddZhtCzzt(nian: number, jidu: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('JIDU', '' + jidu);
  return request(`/api/restricted/AddZhtCzzt`, {
    method: 'POST',
    body: data,
  });
}

/**经营单位获取操作人状态 */
export function AddJydwCzzt(nian: number, jidu: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('JIDU', '' + jidu);
  return request(`/api/restricted/AddJydwCzzt`, {
    method: 'POST',
    body: data,
  });
}

/**负利润清零--修改 */
export function AddCompFlrql(acid: number) {
  const data = new FormData();
  data.append('ACID', '' + acid);
  return request(`/api/restricted/AddCompFlrql`, {
    method: 'POST',
    body: data,
  });
}

/**负利润清零--恢复 */
export function DeleteCompFlrql(acid: number) {
  const data = new FormData();
  data.append('ACID', '' + acid);
  return request(`/api/restricted/DeleteCompFlrql`, {
    method: 'POST',
    body: data,
  });
}

//保存风险管理操作人
export function SaveFxglCzr(zhtczr: Record<string, any>, bm: Record<string, any>) {
  console.log(zhtczr);
  const data = new FormData();
  data.append('CZR', '' + zhtczr);
  data.append('BMID', '' + bm);
  return request(`/api/restricted/SaveFxglCzr`, {
    method: 'POST',
    body: data,
  });
}

/**风险管理获取操作人状态 */
export function AddFxglCzzt(nian: number, jidu: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('JIDU', '' + jidu);
  return request(`/api/restricted/AddFxglCzzt`, {
    method: 'POST',
    body: data,
  });
}

/**保存类别绩效绩效标准修改*/
export function AddLbjxJxbz(valueMap: Record<number, any>, nian: number) {
  const data = new FormData();
  data.append('valueMap', JSON.stringify(valueMap));
  data.append('NIAN', '' + nian);
  return request(`/api/restricted/AddLbjxJxbz`, {
    method: 'POST',
    body: data,
  });
}

/**插入类别绩效除当年其余年的信息*/
export function InsertLbjx(nian: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  return request(`/api/restricted/InsertLbjx`, {
    method: 'POST',
    body: data,
  });
}

/**保存级别系数绩效标准修改*/
export function AddLbjxJbxs(valueMap: Record<number, any>, nian: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('valueMap', JSON.stringify(valueMap));
  return request(`/api/restricted/AddLbjxJbxs`, {
    method: 'POST',
    body: data,
  });
}

/**插入级别系数除当年其余年的信息*/
export function InsertJbxs(nian: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  return request(`/api/restricted/InsertJbxs`, {
    method: 'POST',
    body: data,
  });
}

/**保存调整金额修改*/
export function AddTzje(valueMap: Record<number, any>, ffjd: string) {
  const data = new FormData();
  // data.append('EMID', '' + emid);
  data.append('FFJD', '' + ffjd);
  data.append('valueMap', JSON.stringify(valueMap));
  return request(`/api/restricted/AddTzje`, {
    method: 'POST',
    body: data,
  });
}

//设置绩效锁定状态
export function SetJxsdcz(nian: number, id: number, cz: boolean) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  data.append('ID', '' + id);
  data.append('CZ', cz ? '1' : '0');
  return request(`/api/restricted/SetJxsdcz`, {
    method: 'POST',
    body: data,
  });
}

/**插入绩效锁定除当年其余年的信息*/
export function InserJxsdzt(nian: number) {
  const data = new FormData();
  data.append('NIAN', '' + nian);
  return request(`/api/restricted/InserJxsdzt`, {
    method: 'POST',
    body: data,
  });
}

/**保存年终业绩绩效调整金额修改*/
export function AddNzTzje(valueMap: Record<number, any>, ffjd: string) {
  const data = new FormData();
  // data.append('EMID', '' + emid);
  data.append('FFJD', '' + ffjd);
  data.append('valueMap', JSON.stringify(valueMap));
  return request(`/api/restricted/AddNzTzje`, {
    method: 'POST',
    body: data,
  });
}
